﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FantastPlatform.Community.IMode;
using FantastPlatform.Community.IService;
using FantastPlatform.Framework;
using FantastPlatform.Framework.Core;
using FantastPlatform.Framework.Model;

namespace FantastPlatform.Community.UI.Service
{
    public partial class WorkLogReply : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoginEmployee = Session["User"] as FantastPlatform.Framework.Model.Employee;
            IWorkLogReplyService wlrService = ServiceFactory.CreateService<IWorkLogReplyService>();
            IWorkLogService wlService = ServiceFactory.CreateService<IWorkLogService>();
            switch (Action)
            {
                case "Add":
                    string data = Data;
                    int workLogId = Int32.Parse(Request.QueryString["WorkLogId"]);
                    WorkLogReplyView view = (WorkLogReplyView)JsonToEntity<WorkLogReplyView>(RepairString(data));
                    IWorkLogReply worklogReply = new FantastPlatform.Community.Model.WorkLogReply();
                    if (view != null)
                    {
                        worklogReply.WorkLog = new FantastPlatform.Community.Model.WorkLog();
                        worklogReply.WorkLog.Id = workLogId;
                        worklogReply.Content = view.Content;
                        worklogReply.CreateDate = System.DateTime.Now;
                        worklogReply.PoliceMan = LoginEmployee;
                    //    worklogReply.PoliceMan = new Employee();
                    //    worklogReply.PoliceMan.Id = 568;                    
                    }
                    worklogReply.Enable = true;

                    wlrService.Create(worklogReply);
                    ReturnSuccessMessage("日志回复成功");
                    break;
                case "Get":
                    try
                    {
                        IWorkLog worklog = wlService.Get(Id);
                        object wlobj = new
                        {
                            PoliceMan = worklog.PoliceMan.Name,
                            Title = worklog.Title,
                            Content = worklog.Content,
                            CreateDate = worklog.CreateDate
                        };
                        ReturnObj(wlobj);
                    }
                    catch (Exception ex)
                    {
                        //ReturnErrorMessage(ex.Message);
                    }
                    break;
            }
        }
        public class WorkLogReplyView
        {
            public int Id { get; set; }
            public string Content { get; set; }
        }
    }
}